import json
from json import encoder
from DataCleanHelper import DataCleanHelper
from DataQueryHelper import DataQueryHelper
from Wrapper import Wrapper


if __name__ == "__main__":
    # clean_helper = DataCleanHelper()
    # query_helper = DataQueryHelper()

    # csv_file = clean_helper.PreProcess('user1')

    # print(csv_file)

    # print("总支出: ",csv_file.groupby("收/支")["金额"].sum()["支出"])
    # # print("总收入: ",csv_file.groupby("收/支")["金额"].sum()["收入"])

    # pay = csv_file[csv_file["收/支"] == '支出']["金额"].sum()

    # print(pay)

    # result = {
    #     "pay":pay
    # }
    # # dict to json
    # print(json.dumps(result))
    # # json to dict 
    # temp = json.loads(json.dumps(result))
    # print(temp['pay'])

    # # print("2021年收入明细",query_helper.get_year_income(csv_file,2021))
    # print("2022年支出明细",query_helper.get_year_outcome(csv_file,2022))

    # print(query_helper.get_monthly_outcome(csv_file,2022,11))

    # print(query_helper.sort_by_cost(csv_file,"交易对方",ISoutcome=True))
    # print(query_helper.sort_by_frequency(csv_file,"交易对方"))

    wrapper = Wrapper('user1')

    print("2021年每个月的支出")
    for i in range(12):
        print(json.loads(wrapper.get_monthly_outcome(2021,(i + 1))))
    print("2021年每个月的收入")
    for i in range(12):
        print(json.loads(wrapper.get_monthly_income(2021,(i + 1))))

    print(json.loads(wrapper.sort_by_cost("交易对方",ISoutcome=True)))

    print(json.loads(wrapper.sort_by_frequency("交易对方",ISoutcome=True)))

    print(json.loads(wrapper.query_all("交易对方",2021)))

    print("按月收入：")
    print(json.loads(wrapper.get_income()))
    print("按月支出：")
    print(json.loads(wrapper.get_outcome()))
